package edu.objects;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.appengine.api.datastore.Key;


/**
 * This class is the object for players
 * it hold the player's attributes and behaviors  
 *
 */
@PersistenceCapable
public class Player 
{

	@Persistent
	private Board owner;
	
	@Persistent
	private char[] _currentLetters;
	@Persistent
	private String _name;
	@Persistent
	private int _score;
	
	@PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private Key key;

	private LetterBag _bag;
	
	public void setKey(Key key) {
        this.key = key;
    }
	
	/**
	 * Initialize a player by given the name of the player
	 * @param name - the name of the player
	 */
	public Player(String name, Board board) 
	{
		owner = board;
		_name = name;
		_score = 0;
	}
	
	/**
	 * Returns the name of this player.
	 * @return name - the name of the player
	 */
	public String getName() 
	{
		return _name;
	}
	
	/**
	 * Return array of current letters held by the player.
	 * @return letters array - array of current letters held by the player
	 */
	public char[] getLetters() 
	{
		return _currentLetters;
	}
	
	/**
	 * Trades letters. Need reference to letterbag?
	 */
	public void tradeLetters(char[] lettersToTrade) 
	{
		_currentLetters = owner.getBag().tradeLetters(lettersToTrade);		
	}

	/**
	 * Returns the score of this player.
	 * @return
	 */
	public int getScore() 
	{
		return _score;
	}
	

}




